package com.ytkj.ygAssist.view;

import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.ytkj.ygAssist.main.AssistServer;
import com.ytkj.ygAssist.server.util.FilesUtil;
import com.ytkj.ygAssist.server.util.HttpGetUtil;
import com.ytkj.ygAssist.server.util.MyStringUtil;
import com.ytkj.ygAssist.tools.Config;
import com.ytkj.ygAssist.tools.JFrameListeningInterface;
import com.ytkj.ygAssist.tools.ViewTools;
import com.ytkj.ygAssist.view.myView.ShowMyMenu;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LookAndFeel;
import javax.swing.JPasswordField;
import javax.swing.JCheckBox;
import javax.swing.SwingConstants;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class UserLogin extends JFrame {
	private static final long serialVersionUID = 1L;
	public JFrameListeningInterface foreknowInterface;
	public JPanel contentPane;
	public JTextField userNameTextField;
	public JPasswordField userPasswordField;
	public JLabel label_2;
	public JButton loginButton;
	public JCheckBox remembCheckBox;
	public JCheckBox autologonCheckBox;
	public JLabel lblqq;
	public JLabel lblNewLabel;
	public JLabel lblqq_1;
	public JLabel label_5;
	public JLabel label_6;
	public JButton button_3;

	/**
	 * Create the frame.
	 */
	public UserLogin() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(UserLogin.class.getResource("/images/logo.png")));
		setTitle("智能云购助手");
		setResizable(false);
		setUndecorated(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 430, 340);
		ViewTools.windowMove(this);
		contentPane = new JPanel() {
			private static final long serialVersionUID = 1L;

			@Override
			protected void paintComponent(Graphics g2d) {
				g2d.drawImage(
						Toolkit.getDefaultToolkit().getImage(UserLogin.class.getResource("/images/userLogin/tp1.png")),
						0, 0, getWidth(), getHeight() / 2, this);
				g2d.setColor(new Color(27, 27, 27));
				g2d.fillRoundRect(0, getHeight() / 2, getWidth(), getHeight(), 0, 0);
			}
		};
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		loginButton = new JButton("登    录");
		loginButton.setFont(new Font("微软雅黑", Font.BOLD, 12));
		loginButton.setForeground(Color.WHITE);
		loginButton.setBackground(new Color(221, 4, 4));
		LookAndFeel.installProperty(loginButton, "opaque", Boolean.FALSE);
		loginButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
		loginButton.setBorderPainted(false);
		loginButton.setBounds(109, 299, 199, 35);
		contentPane.add(loginButton);

		JLabel label = new JLabel("用户名:");
		label.setFont(new Font("微软雅黑", Font.BOLD, 14));
		label.setForeground(Color.WHITE);
		label.setBounds(42, 189, 54, 32);
		contentPane.add(label);

		JLabel label_1 = new JLabel("密    码:");
		label_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
		label_1.setForeground(Color.WHITE);
		label_1.setBounds(42, 229, 54, 32);
		contentPane.add(label_1);

		userNameTextField = new JTextField();
		userNameTextField.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				if (e.getKeyCode() == 10) {
					userPasswordField.requestFocus();
				}
				super.keyReleased(e);
			}
		});
		userNameTextField.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				if (userNameTextField.getText().equals("请使用一元云购账户登录")) {
					userNameTextField.setText("");
				}
				if (arg0.getButton() == MouseEvent.BUTTON3) {// 右键点击
					ShowMyMenu.ShowRightClickMenu(userNameTextField, arg0.getX(), arg0.getY());
				}
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				// if (textField.getText().equals("请使用一元云购账户登录")) {
				// textField.setText("");
				// }
			}

			@Override
			public void mouseExited(MouseEvent e) {
				if (userNameTextField.getText().equals("")) {
					userNameTextField.setText("请使用一元云购账户登录");
				}
			}
		});
		userNameTextField.setToolTipText("该一元云购账户仅作为本软件的登录账号，里面使用的账户可自由切换");
		userNameTextField.setFont(new Font("微软雅黑", Font.BOLD, 14));
		userNameTextField.setBounds(109, 188, 197, 32);
		contentPane.add(userNameTextField);

		userPasswordField = new JPasswordField();
		userPasswordField.setFont(new Font("微软雅黑", Font.BOLD, 14));
		userPasswordField.setBounds(109, 230, 197, 32);
		contentPane.add(userPasswordField);

		remembCheckBox = new JCheckBox("记住密码");
		remembCheckBox.setFont(new Font("微软雅黑", Font.BOLD, 13));
		LookAndFeel.installProperty(remembCheckBox, "opaque", Boolean.FALSE);
		remembCheckBox.setBackground(new Color(0, 0, 0, 0));
		remembCheckBox.setForeground(Color.WHITE);
		remembCheckBox.setSelected(true);
		remembCheckBox.setBounds(109, 268, 81, 23);
		contentPane.add(remembCheckBox);

		label_2 = new JLabel();
		label_2.setFont(new Font("微软雅黑", Font.BOLD, 12));
		label_2.setForeground(Color.RED);
		label_2.setHorizontalAlignment(SwingConstants.CENTER);
		label_2.setBounds(308, 310, 114, 15);
		contentPane.add(label_2);

		JLabel registerLabel = new JLabel("注册");
		registerLabel.setHorizontalAlignment(SwingConstants.CENTER);
		registerLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL(Config.yunGouRegisterUrl);
			}
		});
		registerLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
		registerLabel.setForeground(Color.RED);
		registerLabel.setBounds(308, 189, 114, 32);
		registerLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
		contentPane.add(registerLabel);

		JButton btnNewButton_1 = new JButton();
		btnNewButton_1.setBounds(317, 235, 90, 22);
		btnNewButton_1.setCursor(new Cursor(Cursor.HAND_CURSOR));
		contentPane.add(btnNewButton_1);
		btnNewButton_1.setUI(ViewTools.getBasicButtonUI("/images/mainJFrame/addQQ.png"));
		btnNewButton_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL("https://jq.qq.com/?_wv=1027&k=4A84IEk");
			}
		});

		autologonCheckBox = new JCheckBox("自动登录");
		autologonCheckBox.setFont(new Font("微软雅黑", Font.BOLD, 13));
		LookAndFeel.installProperty(autologonCheckBox, "opaque", Boolean.FALSE);
		autologonCheckBox.setForeground(Color.WHITE);
		autologonCheckBox.setBackground(new Color(0, 0, 0, 0));
		autologonCheckBox.setBounds(225, 268, 81, 23);
		contentPane.add(autologonCheckBox);

		JButton btnNewButton = new JButton();
		btnNewButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
		btnNewButton.setUI(ViewTools.getBasicButtonUI("/images/userLogin/zxh.png"));
		btnNewButton.setBorderPainted(false);
		btnNewButton.setBounds(354, 10, 28, 28);
		contentPane.add(btnNewButton);
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				setExtendedState(JFrame.ICONIFIED);
			}
		});

		JButton button_1 = new JButton();
		button_1.setCursor(new Cursor(Cursor.HAND_CURSOR));
		button_1.setUI(ViewTools.getBasicButtonUI("/images/userLogin/tc.png"));
		button_1.setBorderPainted(false);
		button_1.setBounds(392, 10, 28, 28);
		contentPane.add(button_1);
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				System.exit(0);
			}
		});

		String userInfo[] = AssistServer.readerLoginAssistInfo();
		if (userInfo[0] == null || "".equals(userInfo[0])) {
			userNameTextField.setText("请使用一元云购账户登录");
		} else {
			userNameTextField.setText(userInfo[0]);
		}
		userPasswordField.setText(userInfo[1]);

		lblqq = new JLabel("续费联系QQ：" + Config.renewQQ);
		lblqq.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblqq.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL(MyStringUtil.getRelationQQUrl(Config.renewQQ));
			}
		});
		lblqq.setForeground(Color.YELLOW);
		lblqq.setFont(new Font("微软雅黑", Font.BOLD, 14));
		lblqq.setBounds(18, 114, 200, 18);
		contentPane.add(lblqq);

		JButton btnNewButton_2 = new JButton();
		btnNewButton_2.setBounds(225, 114, 77, 21);
		contentPane.add(btnNewButton_2);
		btnNewButton_2.setCursor(new Cursor(Cursor.HAND_CURSOR));
		btnNewButton_2.setUI(ViewTools.getBasicButtonUI("/images/userLogin/qqjt.png"));
		btnNewButton_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL(MyStringUtil.getRelationQQUrl(Config.renewQQ));
			}
		});

		lblNewLabel = new JLabel(Config.yunGouAssistVersions);
		lblNewLabel.setForeground(Color.WHITE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
		lblNewLabel.setBounds(100, 6, 54, 18);
		contentPane.add(lblNewLabel);

		JLabel lblNewLabel_1 = new JLabel(Config.shouyeText1);
		lblNewLabel_1.setForeground(Color.YELLOW);
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
		lblNewLabel_1.setBounds(18, 42, 389, 18);
		contentPane.add(lblNewLabel_1);

		JLabel lblhttpygyuntengkejicn = new JLabel("官网:http://yg.xwintop.com");
		lblhttpygyuntengkejicn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL("http://yg.xwintop.com");
			}
		});
		lblhttpygyuntengkejicn.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblhttpygyuntengkejicn.setForeground(Color.YELLOW);
		lblhttpygyuntengkejicn.setFont(new Font("微软雅黑", Font.BOLD, 14));
		lblhttpygyuntengkejicn.setBounds(18, 90, 213, 18);
		contentPane.add(lblhttpygyuntengkejicn);

		lblqq_1 = new JLabel("请联系商务QQ续费");
		lblqq_1.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblqq_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL(MyStringUtil.getRelationQQUrl(Config.renewQQ));
			}
		});
		lblqq_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblqq_1.setForeground(Color.YELLOW);
		lblqq_1.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		lblqq_1.setBounds(308, 266, 114, 15);
		contentPane.add(lblqq_1);
		lblqq_1.setVisible(false);

		label_5 = new JLabel("或进群交流延长试用");
		label_5.setCursor(new Cursor(Cursor.HAND_CURSOR));
		label_5.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL(Config.assistQQqunUrl);
			}
		});
		label_5.setHorizontalAlignment(SwingConstants.CENTER);
		label_5.setForeground(Color.YELLOW);
		label_5.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		label_5.setBounds(305, 286, 120, 15);
		contentPane.add(label_5);

		label_6 = new JLabel(Config.shouyeText2);
		label_6.setForeground(Color.YELLOW);
		label_6.setFont(new Font("微软雅黑", Font.BOLD, 14));
		label_6.setBounds(18, 66, 389, 18);
		contentPane.add(label_6);

		label_5.setVisible(false);

		String loginConfiguration[] = FilesUtil.readerUserInfo("\\loginConfiguration.log");
		if (loginConfiguration[0] != null) {
			remembCheckBox.setSelected(loginConfiguration[0].equals("true"));
			autologonCheckBox.setSelected(loginConfiguration[1].equals("true"));
		}

		AssistServer.getRenewQQ();
		lblqq.setText("续费联系QQ：" + Config.renewQQ);

		button_3 = new JButton();
		button_3.setCursor(new Cursor(Cursor.HAND_CURSOR));
		button_3.setUI(ViewTools.getBasicButtonUI("/images/mainJFrame/addQQ3.png"));
		button_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				HttpGetUtil.openBrowseURL(Config.assistQQqunUrl);
			}
		});
		button_3.setBounds(218, 140, 90, 22);
		contentPane.add(button_3);

		JLabel label_7 = new JLabel(Config.assistQQqun);
		label_7.setForeground(Color.YELLOW);
		label_7.setFont(new Font("微软雅黑", Font.BOLD, 14));
		label_7.setBounds(18, 142, 200, 18);
		contentPane.add(label_7);
	}

}
